package netty.selfprotocol;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;


public abstract class Message implements Serializable {

    /**
     * 根据消息类型字节，获得对应的消息 class
     * @param messageType 消息类型字节
     * @return 消息 class
     */
    public static Class<? extends Message> getMessageClass(int messageType) {
        return messageClasses.get(messageType);
    }

    private int sequenceId = 0;

    private int messageType;

    public int getSequenceId() {
        return sequenceId;
    }

    public void setSequenceId(int sequenceId) {
        this.sequenceId = sequenceId;
    }

    public abstract int getMessageType();

    private static final Map<Integer, Class<? extends Message>> messageClasses = new HashMap<>();

    public void setMessageType(int messageType) {
        this.messageType = messageType;
    }
}

